/**
A multi shaped mine sweeper game
SDLHexamine  Copyright (C) 2009-2010  Andematunum-Software
(andematunum-software@googlegroups.com)

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "resources.h"
#include "board.h"
#include "SDL.h"
#include <stdlib.h>
#include <iostream>

using namespace std;

SDL_Surface* screen = NULL;

void build_board (int);

static void execute () {
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    throw "Cannot initialize SDL.";
  }
  
  atexit(SDL_Quit);

  screen = SDL_SetVideoMode(1024,768,0,SDL_ANYFORMAT);
  if (screen == NULL) {
    throw "Cannot setup a 1024x768 display.";
  }

  SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,130,130,50));

  Resources* resource = Resources::get_instance();
  resource->test();
  
  build_board(0);

  /**
    * Mine board test
    */
  Uint16 sizes[3] = {16,16,0};
  MineBoardParameters params (
    SHAPE_RECTANGULAR,
    20,
    sizes
  );
  
  MineBoard* board = MineBoard::create<HexagonalMineBoard> (
      params
  );
  board->say_hello();
  MineBoard::destroy();


  SDL_Event evt;
  for (;;) {
    SDL_WaitEvent(&evt);
    if (evt.type == SDL_KEYDOWN) {
      break;
    }
    if (evt.type == SDL_MOUSEBUTTONDOWN) {
      break;
    }
    if (evt.type == SDL_QUIT) {
      break;
    }
  }

  Resources::kill();
}

int main (int argc, char** argv) {
  try {
    execute ();
  }
  catch (char* message) {
    cout << "*** ERROR: " << message << endl;
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}

